//
//  JwLocalCenter.m
//  JwPack
//
//  Created by 陈警卫 on 2024-09-06.
//

#import "JwLocalCenter.h"

#define kJwLocalCenterKey @"kJwLocalCenterKey"

NSString *GV_JwLocalCenter_localBaseModelName = @"";

@implementation JwLocalCenter

/// 单例
+ (JwLocalCenter *)shared {
    static JwLocalCenter *sharedObject;
    static dispatch_once_t token;
    dispatch_once(&token, ^{
        sharedObject = [[JwLocalCenter alloc] initShared];
    });
    return sharedObject;
}

- (instancetype)init {
    return [[self class] shared];
}

- (instancetype)initShared {
    self = [super init];
    if (self) {
        [self setupData];
    }
    return self;
}

- (void)setupData {
    id value = [JwUserDefaults objectForKey:kJwLocalCenterKey];
    if (GV_JwLocalCenter_localBaseModelName.length > 0) {
        self.localBaseModel = [[NSClassFromString(GV_JwLocalCenter_localBaseModelName) alloc] initWithDictionary:value error:nil];
    } else {
        self.localBaseModel = value;
    }
}

- (void)save {
    NSDictionary *dict = [self.localBaseModel toDictionary];
    [JwUserDefaults setSyncObject:dict key:kJwLocalCenterKey];
}

- (void)clean {
    [JwUserDefaults removeObjectForKey:kJwLocalCenterKey];
}




@end
